/*
* ============================================================================
*  Name        : sea_link.h
*  Part of     : Finite state machine utilities
*  Description : Link object definition
*  Version     : %version: %
*  
*
* ============================================================================
*/
/**
 * @file sea_link.h
 * @brief 
 * @ref sea::Link
 *
 * @ingroup AssociationUtilities
 */
#if !defined( __sea_link_h__ )
#define __sea_link_h__ 

#include "sea_object.h"

namespace sea
{
    /** 
     * @class Link sea_link.h "sea_link.h"
     * @brief sea::Link object 
     *      Implements objects associations \n \b horizontal (via m_RightObj and m_LeftObj) \n
     *      and \n \b vertical (by being derived from Object)
     * @ingroup AssociationUtilities
     */
    class Link: public Object
    {
    public:

        /**
         * Constructor
         *
         * @param host Hosting object for the link
         * @param id Association Id
         */
        Link( Object* host, Association id = 0 );

        virtual ~Link( );

        /**
         * Get right object ptr
         *
         * @return Right object ptr
         */
        sea::ref< Link > right_link( ) { return m_right; }

        /**
         * Get left object ptr
         *
         * @return Left object ptr
         */
        sea::ref< Link > left_link( ) { return m_left; }

        /**
         * Set right link
         *
         * @param link pointer to the right Link object
         */
        void set_right_link( sea::ref< Link > link ) 
        {
            m_right = link; 
        }

        /**
         * Set left link
         *
         * @param link pointer to the left Link object
         */
        void set_left_link( sea::ref< Link > link )
        { 
            m_left = link; 
        }

        /**
         * Get Right neighbour
         *
         * @param id Association id
         *
         * @return Right neighbour object pointer
         */
        sea::ref< Link > down_link( Association id )
        { 
            return reinterpret_cast< Link* > ( Object::get_right_obj( id ).get( ) );
        }

        /**
         * Get Left neighbour
         *
         * @param id Association id
         *
         * @return Left neighbour object pointer
         */
        sea::ref< Link > up_link( Association id )
        {
            return reinterpret_cast< Link* > ( Object::get_left_obj( id ).get( ) ); 
        }

        /**
         * Get association
         *
         * @return Association
         */
        Association get_association( ){ return m_id; }

        /**
         * Get host object
         *
         * @return Object* Host object
         */
        sea::aref host( ) { return m_host; }

    private:
        sea::aref m_host;              ///< Host object
        sea::ref< Link > m_right;      ///< Right associtation
        sea::ref< Link > m_left;       ///< Left association
        Association m_id;              ///< Association
    };
}

#endif // #if !defined( __sea_link_h__ )
